//  用户上滑页面 滚动条触底 开始加载下一页数据
// 1.找到滚动条触底事件  微信小程序官方开发文档 
// 2.判断还有没有下一页数据
  // 1.获取总页数
      // 总页数 = math.ceil(总条数/页容量 pagesize)
  // 2.获取当前页码
  // 3.判断一下  当前的页码是否大于等于 总页数
  //   表示 没有下一页数据
// 3.假如没有下一页数据  弹出提示
// 4.假如还有下一页数据  来加载下一页数据
    // 1.当前页码++
    // 2.重新发送请求
    // 3.数据请求回来 要对data中的数组进行 拼接 而不是全部替换
// 下拉刷新 
  // 1.触发下拉刷新事件
  // 2.重置数据数组
  // 3.重置页码 设置为1
  // 4.关闭下拉刷新 wx.stopPullDownRefresh()
Page({
  // 页面的初始数据
  data: {
    // 导航分类
    tabs:[
      {
        id:1,
        name:"综合",
        isActive:true
      },
      {
        id:2,
        name:"销量",
        isActive:false
      },
      {
        id:3,
        name:"价格",
        isActive:false
      },
    ],
    // 商品列表
    goodList:[
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:1,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:2,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:3,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:4,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:5,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:6,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:7,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:8,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:9,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:10,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:11,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:12,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:13,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:14,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:15,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:16,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:17,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:18,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:19,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:20,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:21,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:22,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:23,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
      {
        img:"//img12.360buyimg.com/focus/s140x140_jfs/t1/131424/31/274/19042/5ecb3bc2E96ef8448/0188085e6fd6cd12.png",
        id:24,
        title:"日本进口冰箱密封保鲜盒果蔬收纳盒超大容量加厚食物干果储存盒",
        coin:"￥999"
      },
    ]

  },
  // 接口需要的参数
  QueryParams:{
    query:"",
    cid:"",
    pagenum:1,
    pagesize:10,
  },
  // 总页数
  // totalpages:1,
  handleTabsItemchange(e){
    console.log(e)
    // 获取点击的标题索引
    const {index} = e.detail
    // 修改原数组
    let {tabs} = this.data
    tabs.forEach((v,i) => i===index?v.isActive=true:v.isActive=false);
    // 赋值
    this.setData({
      tabs
    })
  },
// 生命周期函数--监听页面加载
  onLoad: function (options) {
    // 先获取到商品的id
    // this.QueryParams.cid=options.cid
  },
  /**
   * 获取商品类表数据
   */
    // getgoodslist(){
    //   request({url:"/Getcata",data:this.QueryParams}).then(request => {
    //   // 获取总条数
    //   const total = res.msg.total
    //   // 计算总页数
    //   this.totalpages=Math.ceil(total/this.QueryParams.pagesize)
    //   // 拼接数据列表
    //   var newlist=this.data.goodList.concat(result.data)
    //   this.setData({
    //       // 赋值给商品列表
    //       goodList:newlist
    //     })
    //   // 关闭下拉刷新
    //   wx.stopPullDownRefresh()
    //   })
    // },
  
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {   
    console.log("监听用户下拉动作")
    // // 重置数组 清空数组
    // this.setData({
    //   goodList:[]
    // })
    // this.QueryParams.pagenum = 1
    // // 发送请求
    // this.getgoodslist()
    // // 关闭下拉刷新窗口
    // wx.stopPullDownRefresh()
  },

// 页面上拉触底事件的处理函数
  // onReachBottom: function () {
  //   // 判断是否还有下一页数据 没有就提示 有就重新加在数据
  //   if(this.QueryParams.pagenum >= this.totalpages){
  //     // 没有下一页提示
  //     wx.showToast({
  //       title: '我是有底线的',
  //       // icon:"loading",
  //       // image:"",
  //       // duration:"2000",
  //       // mask:"false",
  //       // success:(res) =>{
  //       // }
  //     })
  //   }else{
  //     // 还有下一页  页码自增  重新加载
  //     this.QueryParams.pagenum++ ;
  //     this.getgoodslist()
  //   }
  // },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})